import time
import pytest
import allure
import TestCase

from Base.InitDriver import init_driver
from Page.CommonPage import CommonPage
from Utils.XiaoMaUtils import XiaoMaUtils


@allure.feature('TestCase_06: 添加技能后技能列表页正常展示添加的技能		')
@allure.issue(
    'https://www.tapd.cn/54441127/sparrow/tcase/view/1154441127001070659?url_cache_key=5b07a59231afaf505fb7dc2f4205dfae')
class TestCaseYomi06:
    def setup_class(self):
        self.driver = init_driver()
        # 实例化页面
        # 桌面
        self.launcher_index_page = CommonPage(self.driver).get_launcher_index_page()
        self.launcher_app_list_page = CommonPage(self.driver).get_launcher_app_list_page()
        # 语音训练
        self.yomi_index_page = CommonPage(self.driver).get_yomi_index_page()
        self.yomi_car_control_page = CommonPage(self.driver).get_yomi_car_control_page()
        self.yomi_car_window_page = CommonPage(self.driver).get_yomi_car_window_page()
        self.yomi_delete_toast_page = CommonPage(self.driver).get_yomi_delete_toast_page()
        self.yomi_details_page = CommonPage(self.driver).get_yomi_details_page()
        self.yomi_music_page = CommonPage(self.driver).get_yomi_music_page()
        self.yomi_navigation_page = CommonPage(self.driver).get_yomi_navigation_page()
        self.yomi_new_page = CommonPage(self.driver).get_yomi_new_page()
        self.yomi_online_radio_page = CommonPage(self.driver).get_yomi_online_radio_page()
        self.yomi_passage_page = CommonPage(self.driver).get_yomi_passage_page()
        self.yomi_quit_toast_page = CommonPage(self.driver).get_yomi_quit_toast_page()
        self.yomi_radio_page = CommonPage(self.driver).get_yomi_radio_page()
        self.yomi_skill_list_page = CommonPage(self.driver).get_yomi_skill_list_page()
        self.yomi_skill_page = CommonPage(self.driver).get_yomi_skill_page()
        self.yomi_temperature_page = CommonPage(self.driver).get_yomi_temperature_page()
        self.yomi_volume_page = CommonPage(self.driver).get_yomi_volume_page()
        self.yomi_weather_page = CommonPage(self.driver).get_yomi_weather_page()
        self.yomi_delete_page = CommonPage(self.driver).get_yomi_delete_page()

    def teardown_class(self):
        XiaoMaUtils.close_app('launcher')
        # XiaoMaUtils.clear_data('personal')
        self.driver.quit()

    @allure.story('step1:点击应用页')
    @pytest.mark.run(order=61)
    def test_yomi_06_1_click_list(self):
        try:
            self.launcher_index_page.click_app_list()
        except Exception as e:
            raise e
        finally:
            allure.attach(self.driver.get_screenshot_as_png(), XiaoMaUtils.get_current_time(),
                          allure.attachment_type.PNG)

    @allure.story("step2: 点击列表中的yomi训练图标,进入后删除上次添加的技能")
    @pytest.mark.run(order=62)
    def test_yomi_06_2_click_yomi(self):
        try:
            self.launcher_app_list_page.click_appname(TestCase.YOMI)
            a = self.yomi_skill_list_page.is_display_yomi_skill_list()
            if a == True:
                self.yomi_skill_list_page.click_skill_name_title()
                self.yomi_delete_page.is_display_yomi_delete()
                self.yomi_delete_toast_page.click_no()
                self.yomi_delete_toast_page.click_sure()
                self.yomi_index_page.is_display_yomi_index()
            else:
                self.yomi_index_page.is_display_yomi_index()
        except Exception as e:
            raise e
        finally:
            allure.attach(self.driver.get_screenshot_as_png(), XiaoMaUtils.get_current_time(),
                          allure.attachment_type.PNG)

    @allure.story("step3: 点击添加技能,查看是否进入添加技能页,输入框输入'早上好'唤醒词")
    @pytest.mark.run(order=63)
    def test_yomi_06_3_click_yomi(self):
        try:
            self.yomi_index_page.click_create()
            self.yomi_details_page.is_display_yomi_details()
            self.yomi_details_page.input_tip()
        except Exception as e:
            raise e
        finally:
            allure.attach(self.driver.get_screenshot_as_png(), XiaoMaUtils.get_current_time(),
                          allure.attachment_type.PNG)

    @allure.story("step4: 点击电台,进入后点击确认,添加一个默认电台,点击确认查看技能列表是否含有")
    @pytest.mark.run(order=64)
    def test_yomi_06_4_click_yomi(self):
        try:
            self.yomi_details_page.click_add_skill()
            self.yomi_skill_page.click_ability_title(index=5)
            self.yomi_radio_page.is_display_yomi_radio()
            self.yomi_radio_page.click_sure()
            text1 = self.yomi_details_page.get_ele_text(self.yomi_details_page.get_added_name())
            if text1 == '播放电台':
                print("添加技能成功")
            else:
                print("添加技能失败")
        except Exception as e:
            raise e
        finally:
            allure.attach(self.driver.get_screenshot_as_png(), XiaoMaUtils.get_current_time(),
                          allure.attachment_type.PNG)

    @allure.story("step5: 点击保存后查看技能列表是否含有")
    @pytest.mark.run(order=65)
    def test_yomi_06_5_click_yomi(self):
        try:
            self.yomi_details_page.click_save()
            self.yomi_skill_list_page.is_display_yomi_skill_list()
            text1 = self.yomi_skill_list_page.get_ele_text(self.yomi_skill_list_page.get_skill_name())
            if text1 == '早上好':
                text2 = self.yomi_skill_list_page.get_ele_text(self.yomi_skill_list_page.get_skill_name_title())
                if text2 == '技能1':
                    print("技能显示正常")
                else:
                    print("技能显示失败")
            else:
                print("添加技能失败")
        except Exception as e:
            raise e
        finally:
            allure.attach(self.driver.get_screenshot_as_png(), XiaoMaUtils.get_current_time(),
                          allure.attachment_type.PNG)


if __name__ == '__main__':
    # pass
    pytest.main("-s testcase_yomi_06.py")
